The Use of UNIX Regular Expressions Regular Expressions are a standard function of the UNIX operating system. They are used to search for or replace text located within files or from the keyboard. The UNIX commands GREP (Global Regular Expression Print) and SUBS (SUBstitue Strings) are used to manipulate text via regular expressions. There are various characters that the reuglar expression processor sees as having special meaning. These special characters are: . period matches any alpha-numeric character ^ caret matches the beginning of the line zgrep ^#include will find all line beginning with #include $ dollar matches the end of the line zgrep }$ will find all lines ending with a close brace * asterisk Repeats any number of the last pattern. Includes zero repetitions. zgrep test* finds lines with at least one occurence of test. [] brakets specifies a set of given characters. zgrep ^[abcd0123] will find lines begining with any one of the specified characters. - hyphen denotes a range of characters. zgrep [A-Z0-9]$ finds lines ending in a capital letter or a number. \ backslash removes the special characteristics of a character. zgrep \$ finds dollar signs in a line of text. zgrep ^[A-D].*\.C$ will locate all .C files that begin with the letters A through D. Notice the escaping of the '.' before the C extent. , comma separates multiple reglar expressions zgrep ^[A-D],EXE$ will locate all files that begin with the letters A through D and All files that end in EXE. NOTE: When the caret (^) is used as the first character after a left square braket, it reverses the meaning of the search. zgrep [^A-Z]& will find all lines not ending with a capital letter. zgrep ^[^A-Z] will find all lines not begining with a capital letter. Note that in this case the caret is used in both contexts. Pattern Segments At times is is useful to denote a segment of the search string. In ZGrep is a powerful tool to find any combination of file names. \( denotes the beginning of a segment. \) denotes the end of a segment. The best way to understand this usage is by example. To find all files that begin with the letters A-M \(.*\) [A-M] In this command the use of the '.*' within the first segment is a powerful construction. It is the same as the DOS '*' wild card. The period followed by the asterisk means repeat any character any number of times. The files of the file is the first part of the search.